package com.weidft.dal.warehouse.dao.ibatis;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.springframework.orm.ibatis.support.SqlMapClientDaoSupport;

import com.weidft.dal.warehouse.dao.ICangkuDao;
import com.weidft.dal.warehouse.daoobject.ChangkuChuDO;
import com.weidft.dal.warehouse.daoobject.ChangkuRuDO;

public class IBatisCangkuDao  extends SqlMapClientDaoSupport implements ICangkuDao
{

    @Override
    public void deleteChangkuRu(int id)
    {
        getSqlMapClientTemplate().delete("WAREHOUSE_CANGKU_RU.deleteByid", id);
    }

    @Override
    public ChangkuRuDO getChangkuRuById(int id)
    {
        return  (ChangkuRuDO)getSqlMapClientTemplate().queryForObject("WAREHOUSE_CANGKU_RU.findById", id);
    }

    @Override
    public int saveChangkuRu(ChangkuRuDO ru)
    {
        int id =  (Integer) getSqlMapClientTemplate().insert("WAREHOUSE_CANGKU_RU.insert",ru);
        return id;
    }

    @Override
    public void updateChangkuRu(ChangkuRuDO ru)
    {
        getSqlMapClientTemplate().update("WAREHOUSE_CANGKU_RU.update", ru);
    }

    @Override
    public Integer countCangKuRu(ChangkuRuDO ru)
    {
        return (Integer) getSqlMapClientTemplate().queryForObject("WAREHOUSE_CANGKU_RU.count", ru);
    }

    @Override
    public List<ChangkuRuDO> listCangKuRu(ChangkuRuDO ru)
    {
        return getSqlMapClientTemplate().queryForList("WAREHOUSE_CANGKU_RU.list",ru);
    }

    @Override
    public Integer countCangKuChu(ChangkuChuDO chu)
    {
        return (Integer) getSqlMapClientTemplate().queryForObject("WAREHOUSE_CANGKU_CHU.count", chu);
    }

    @Override
    public void deleteChangkuChu(int id)
    {
        getSqlMapClientTemplate().delete("WAREHOUSE_CANGKU_CHU.deleteByid", id);        
    }

    @Override
    public ChangkuChuDO getchangkuChuByid(int id)
    {
        return  (ChangkuChuDO)getSqlMapClientTemplate().queryForObject("WAREHOUSE_CANGKU_CHU.findById", id);
    }

    @Override
    public List<ChangkuChuDO> listCangKuChu(ChangkuChuDO chu)
    {
        return getSqlMapClientTemplate().queryForList("WAREHOUSE_CANGKU_CHU.list",chu);
    }

    @Override
    public int saveChangkuChu(ChangkuChuDO chu)
    {
        int id =  (Integer) getSqlMapClientTemplate().insert("WAREHOUSE_CANGKU_CHU.insert",chu);
        return id;
    }

    @Override
    public void updateChangkuChu(ChangkuChuDO chu)
    {
        getSqlMapClientTemplate().update("WAREHOUSE_CANGKU_CHU.update", chu);        
    }

    @Override
    public void updateAmount(int id, float num)
    {
        Map<String, Object> map = new HashMap<String, Object>();
        map.put("id", id);
        map.put("num",num);
        getSqlMapClientTemplate().update("WAREHOUSE_CANGKU_RU.update_amount", map);
    }

    @Override
    public int getchangkuchuMaxId()
    {
        Object o = getSqlMapClientTemplate().queryForObject("WAREHOUSE_CANGKU_CHU.maxid");
        if (o == null)
        {
            return 0;
        }
        return (Integer)o;
    }

    @Override
    public int getchangkuruMaxId()
    {
        Object o = getSqlMapClientTemplate().queryForObject("WAREHOUSE_CANGKU_RU.maxid");
        if (o == null)
        {
            return 0;
        }
        return (Integer)o;
    }

}
